package xyz.yuzegod.megawalls.classes.normal.dreadlord;

import org.bukkit.entity.Player;
import xyz.yuzegod.megawalls.MegaWalls;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Material;
import org.bukkit.event.block.BlockBreakEvent;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.util.ItemUtils;
import xyz.yuzegod.megawalls.util.PlayerUtils;
import xyz.yuzegod.megawalls.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.CollectSkill;

public class FourthSkill extends CollectSkill
{
    public FourthSkill(final Classes classes) {
        super("暗物质", classes);
    }
    Map<Player,Material> next=new HashMap<>();
    //0=cp,1=leg,2=boots
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 0.6;
            }
            case 2: {
                return 0.8;
            }
            case 3: {
                return 1.0;
            }
            default: {
                return 0.6;
            }
        }
    }
    
    public double getChestplate(final int level) {
        switch (level) {
            case 1: {
                return 0.4;
            }
            case 2: {
                return 0.5;
            }
            case 3: {
                return 0.6;
            }
            default: {
                return 0.4;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7挖矿时有§a" + StringUtils.percent(this.getAttribute(level)) + "几率掉落铁锭,");
            lore.add("    §7挖任何矿物都有§a" + StringUtils.percent(this.getChestplate(level)) + "§7几率");
            lore.add("    §7掉落一件铁护甲。");
            return lore;
        }
        lore.add(" §8▪ §7挖矿时有§8" + StringUtils.percent(this.getAttribute(level - 1)) + " ➜");
        lore.add("    §a" + StringUtils.percent(this.getAttribute(level)) + "§7几率掉落铁锭,");
        lore.add("    §7挖任何矿物都有§8" + StringUtils.percent(this.getAttribute(level - 1)) + " ➜");
        lore.add("    §a" + StringUtils.percent(this.getChestplate(level)) + "§7几率");
        lore.add("    §7掉落一件铁护甲。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill4Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill4Level();
    }
    
    @Override
    public void onBlockBreak(final KitStatsContainer kitStats, final BlockBreakEvent e) {
        if (ItemUtils.matchMaterial(e.getBlock(),Material.COAL_ORE)) {
            PlayerUtils.gatheringItem( new ItemStack(Material.IRON_INGOT),e);
            e.getBlock().setType(Material.AIR);
        }
        if ((ItemUtils.isOreResource(e.getBlock())) && MegaWalls.getRandom().nextInt(200) <= this.getAttribute(kitStats.getSkill4Level()) * 100.0) {
            PlayerUtils.gatheringItem( new ItemStack(Material.IRON_INGOT),e);
            if ((ItemUtils.isOreResource(e.getBlock())) && MegaWalls.getRandom().nextInt(200) <= this.getChestplate(kitStats.getSkill4Level()) * 100.0) {
                if (!next.containsKey(e.getPlayer())){
                    next.put(e.getPlayer(),Material.IRON_CHESTPLATE);
                }
                PlayerUtils.gatheringItem(new ItemStack(next.get(e.getPlayer())),e);
                if (next.get(e.getPlayer())==Material.IRON_CHESTPLATE){
                    next.replace(e.getPlayer(),Material.IRON_LEGGINGS);
                } else if (next.get(e.getPlayer())==Material.IRON_LEGGINGS) {
                    next.replace(e.getPlayer(),Material.IRON_BOOTS);
                } else if (next.get(e.getPlayer())==Material.IRON_BOOTS) {
                    next.replace(e.getPlayer(),Material.IRON_CHESTPLATE);
                }

            }
        }
    }

}
